package com.kzj.fun.graph;

import com.kzj.common.exception.ExceptionEnum;
import com.kzj.common.exception.SystemException;

import java.awt.*;

public class Rectangle extends FillableGraph{
    protected final int x,y,width,height;

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

        public Rectangle(Point point1, Point point2, int stroke, Color color, boolean full){
        super(stroke,color,full);
         x=Math.min(point1.x,point2.x);
         y=Math.min(point1.y,point2.y);
         width=Math.abs(point1.x-point2.x);
         height=Math.abs(point1.y-point2.y);
    }
    @Override
    public void draw(Graphics g) {

        if(g instanceof  Graphics2D){
            Graphics2D g2d=(Graphics2D) g;
            g2d.setColor(this.color);
            if(this.full){
                g2d.fillRect(x,y,width,height);
            }else{
                g2d.setStroke(new BasicStroke(this.stroke));
                g2d.drawRect(x,y,width,height);
            }
            System.out.println(String.format("x: %d,y: %d,width: %d,height: %d",x,y,width,height));
        }else throw new SystemException(ExceptionEnum.INNER_PARAM_EXCEPTION);

    }
}
